import torch
from PIL import Image
import cv2,onnx
import onnxruntime
from torch import nn
import torch.utils.model_zoo as model_zoo
from PIL import Image
import torchvision.transforms as transforms
import torch.onnx
def predict_with_hub():
    p="./runs/train/exp/weights/last.pt"
    model = torch.hub.load('ultralytics/yolov5', 'custom', path=p)
    # Images
    imgs = ['../datasets/steel/test_dataset/1C8576CB.jpg',
                '../datasets/steel/test_dataset/FE63E97C.jpg',
                ]  # filename
    img1 = Image.open(imgs[0])  # PIL image
    img2 = cv2.imread(imgs[1])[..., ::-1]  # OpenCV image (BGR to RGB)
    imgs = [img1, img2]  # batch of images
    # Inference
    results = model(imgs, size=640)  # includes NMS
    # Results
    results.print()
    results.show()
    results.save()  # or .show()
    print (results.xyxy[0])  # img1 predictions (tensor)
    print (results.pandas().xyxy[0])  # img1 predictions (pandas)
    